package com.ctgu.j13.service;

import com.ctgu.j13.dao.CustomerMapper;
import com.ctgu.j13.vo.Customer;
import com.ctgu.j13.vo.CustomerExample;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerService {
    @Resource
    private CustomerMapper customerMapper;

    public boolean save(Customer customer)
    {
        CustomerExample example =new CustomerExample();
//        example.createCriteria().andCustomerIdEqualTo(customer.getCustomerId());
        example.createCriteria().andCustomerNameEqualTo(customer.getCustomerName());
        List<Customer> customerList=customerMapper.selectByExample(example);
        if(customerList.size()>0)
            return false;

        return customerMapper.insert(customer)>0?true:false;
    }

    public List<Customer> customerList()
    {
//        List<Customer> customerList= customerMapper.selectAllCustomer();
//        for ( Customer s : customerList) {
//            System.out.println(s.getCustomerId()+"  "+s.getCustomerName()+"  "+s.getCustomerGender());
//        }
        CustomerExample example =new CustomerExample();
        example.createCriteria().andCustomerNameIsNotNull();
        List<Customer> customerList=customerMapper.selectByExample(example);
        return customerList;
    }

    public boolean delete(Integer id)
    {
//        customerMapper.deleteByPrimaryKey(id);
        return customerMapper.deleteByPrimaryKey(id)>0?true:false;
    }

}
